package org.sith.taskrunner.ejb.transformers;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import org.sith.taskrunner.api.exceptions.TransformInputDataException;
import org.sith.taskrunner.api.transformer.InputDataTransofrmer;
import org.sith.taskrunner.temp.tasks.distribution.NormalDistributionInputData;

public class StringNormalDataTransformer implements
		InputDataTransofrmer<NormalDistributionInputData, String> {

	@Override
	public NormalDistributionInputData transform(String inputData)
			throws TransformInputDataException {
		List<Double> sequence= new ArrayList<Double>();
		StringTokenizer st = new StringTokenizer(inputData,", ");
		while(st.hasMoreTokens()){
			try{
			sequence.add(Double.parseDouble(st.nextToken()));
			} catch (NumberFormatException e){
				throw new TransformInputDataException("Your input data is not valid. Only integer alow", e);
			}
		}
		return new NormalDistributionInputData(sequence);
	}
}
